﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.WaterPurchase;

namespace University.Workshop.Presentation.WaterPurchase
{
    /// <summary>
    /// Interaction logic for PageFirstStepRegisterWaterPurchase.xaml
    /// </summary>
    public partial class PageFirstStepRegisterWaterPurchase : Page, IFirstStepForRegisterWaterPurchase
    {
        PresenterRegisterNewWaterPurchaseView pInternal;
        PresenterFirstStepForRegisterWaterPurchase pFirstStepForRegisterWaterPurchase;

        public PageFirstStepRegisterWaterPurchase(PresenterRegisterNewWaterPurchaseView pExternal)
        {
            InitializeComponent();
            pInternal = pExternal;

            /*CapacityLbl.Content = "";
            PersonNamesLbl.Content = "";
            PersonLastNamesLbl.Content = "";*/

            pFirstStepForRegisterWaterPurchase = new PresenterFirstStepForRegisterWaterPurchase(this);
        }


        private void CantCupyPasteOrCut(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Copy)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Cut)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Paste)
                e.Handled = true;
        }

        private void LicencePlateTxt_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {

        }

        private void LicencePlateTxt_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
            }
            if (e.Key == Key.Enter)
            {
                Boolean existeCisterna;

                existeCisterna = pFirstStepForRegisterWaterPurchase.VerifyIfCisternExist();
                if (existeCisterna)
                {
                    LicencePlateTxt.IsReadOnly = true;
                }
            }
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Registrar Compra";
        }





        #region IFirstStepForRegisterWaterPurchase Members

        public string LicencePlate
        {
            get
            {
                return LicencePlateTxt.Text;
            }
            set
            {
                LicencePlateTxt.Text = value;
            }
        }

        public string Capacity
        {
            get
            {
                return CapacityLbl.Content.ToString();
            }
            set
            {
                CapacityLbl.Content = value;
            }
        }

        public string PersonNames
        {
            get
            {
                return PersonNamesLbl.Content.ToString();
            }
            set 
            {
                PersonNamesLbl.Content = value;
            }
        }

        public string PersonLastNames
        {
            get
            {
                return PersonLastNamesLbl.Content.ToString();
            }
            set 
            {
                PersonLastNamesLbl.Content = value;
            }
        }

        #endregion

        #region IRegisterBasicView Members

        public Model.WaterPurchase WaterPurchaseToRegister
        {
            get;
            set;
        }

        public void Update()
        {
            pFirstStepForRegisterWaterPurchase.UpdateData(); 
        }

        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MessageBox.Show(value);
            }
        }

        public string ErrorMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MessageBox.Show(value);
            }
        }

        public void ChargeDataToBasic()
        {
            pFirstStepForRegisterWaterPurchase.ChargeDataPerson();
        }

        public void GoNextPage()
        {
            pInternal.GoStepTwo();
        }

        public void GoBackPage()
        {
        }

        #endregion

        private void LicencePlateTxt_LostFocus(object sender, RoutedEventArgs e)
        {

        }

        private void LicencePlateTxt_TouchEnter(object sender, TouchEventArgs e)
        {

        }

    }
}
